package offer.easy;

public class RotateArray {

    public static int minRotateNumber(int[] array) {
        int low = 0;
        int high = array.length-1;
        int mid = 0;
        int temp = 0;
        if (array.length == 0) {
            return 0;
        }
        while(low < high) {
            if (array[low] <= array[low+1] && low < high) {
                low++;
            } else {
                mid = low+1;
                break;
            }
            if (array[high] >= array[high-1] && high > low) {
                high--;
            } else {
                mid = high-1;
                break;
            }
        }
        temp = array[high]>=array[low]?array[low]:array[high];
        temp = array[mid]>=temp?temp:array[mid];
        return temp;
    }

    public static void main(String[] args) {
        int[] array = {6501,6828,6963,7036,7422,7674,8146,8468,8704,8717,9170,9359,9719,9895,9896,9913,9962,154,293,334,492,1323,1479,1539,1727,1870,1943,2383,2392,2996,3282,3812,3903,4465,4605,4665,4772,4828,5142,5437,5448,5668,5706,5725,6300,6335};
        System.out.println(minRotateNumber(array));
    }
}
